package edu.siu.math.egut.egut;


/**
 * This class is used to represent a LiE Matrix
 * 
 * @author Joe Pleso
 *
 */
public class LiEMatrix extends AbstractLiEObject {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private final int[][] result; 
    
    /**
	 * Parses matrix output from LiE into a int[][].
	 * 
	 * @param s the string from LiE
	 * 
	 */
    public LiEMatrix(String s){
	super(LiEType.MAT);
	s = s.trim();
	s = s.substring(0, s.length() - 1);
	s.trim();

	
	String[] values = s.split(Character.toString(Algorithms.LIE_NEWLINE));
	
	result = new int[values.length][];
	
	for (int i = 0; i < values.length; i++){
	    
	    result[i] = (int[]) 
	    (new LiEVector (values[i].substring(1)).getJavaObject());
	    
	}
	
	
	
    }
    
    /**
     *Convert an int[][] to a LiE matrix.
     * 
     * @param v the int[][] to convert
     */
    public LiEMatrix (int[][] v){
	super(LiEType.MAT);
	result = v;
    }
    
    
    public Object getJavaObject() {
	
	return result;
    }
    	/**
	 * Convert an int[][] into a string that LiE will parse as a matrix.
	 * 
	 * 
	 * @return a string representing a LiE matrix
	 */
	public String toString (){
	    StringBuffer sb = new StringBuffer();
	    sb.append(Algorithms.LIE_LEFT_SQUARE_BRACKET);
	    for (int i = 0; i < result.length; i++){
		
	    
		sb.append(new LiEVector(result[i]).toString());
		sb.append( Character.toString(Algorithms.LIE_COMMA));}
	    sb.setCharAt(sb.length() - 1, Algorithms.LIE_RIGHT_SQUARE_BRACKET);
	    return sb.toString();
	    
	}
	
	
	
}
